package org.xiaojinlong.playground;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author Jin Long
 *         2015/10/8
 */
public class CreatingGenericObjectArray {
    private static class Node<Item> {
        Item item;
        Node<Item> next;

        @Override
        public String toString() { return item.toString(); }
    }

    public static void main(String[] args) {
        // foo是一个对象数组，只不过这个对象使用了泛型
        // 要注意这和泛型数组不一样，Java目前不支持创建泛型数组
        Node<String>[] foo = (Node<String>[])new Node[2];
        Node<String> a = new Node<>();
        a.item = "happy";
        Node<String> b = new Node<>();
        b.item = "birthday";
        a.next = b; b.next = null;
        foo[0] = a; foo[1] = b;

        for (Node<String> stringNode : foo) {
            System.out.println(stringNode);
        }
    }
}
